<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    response.setHeader("X-Frame-Options", "SAMEORIGIN");
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <jsp:include page="../../public/public.jsp"/>
<body>
<!-- 菜单按钮、搜索框 -->
<div id="menu_tb" style="height:auto;margin-top: 20px;">
    <table cellspacing="0" cellpadding="0" style="border-bottom: 1px solid #cccccc" width="100%">
        <tr>
            <td style="height:50px;padding-left:20px">
                登录账户:<input id="userId" class="easyui-textbox" data-options="width:100"/>
                企业名称:<input id="name" class="easyui-textbox" data-options="width:100"/>
                <a href="javascript:void(0)" onclick="init()" class="easyui-linkbutton"
                   data-options="width:100,height:40,iconCls:'icon-search'">搜&nbsp;&nbsp;&nbsp;&nbsp;索</a>
                <a href="javascript:void(0)" onclick="chongzhi()" class="easyui-linkbutton"
                   data-options="width:100,height:40,iconCls:'icon-remove'">重&nbsp;&nbsp;&nbsp;&nbsp;置</a>
            </td>
        </tr>
    </table>

    <table style="height: auto;">
        <tr>
            <td>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-mini-refresh" plain="true"
                   onclick="refresh()">刷新列表</a>
            </td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
            <td>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" plain="true"
                   onclick="queryCompanyBase()">查看企业基本信息</a>
            </td>

            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
            <td>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" plain="true"
                   onclick="viewEmployee()">查看企业从业人员</a>
            </td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>

            <td>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" plain="true"
                   onclick="viewcertificatoryCampany()">查看企业证书</a>
            </td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>


            <td>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-man" plain="true"
                   onclick="certificatoryCampany()">授予证书</a>
            </td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
        </tr>
    </table>
</div>
<!-- end -->
<table id="dg" style="width:100%;height: 320px;" data-options="
				url:'<%=basePath %>companyMange/queryCompanyList',
				rownumbers:true,
				singleSelect:true,
				autoRowHeight:false,
				pagination:true,
				pageSize:10">
    <thead>
    <tr>
        <th field="name" width="15%" align="center">企业名称</th>
        <th field="city" width="18%" align="center">城市</th>
        <th field="address" width="15%" align="center">地址</th>
        <th field="userId" width="15%" align="center">注册账号ID</th>
        <th field="address" width="15%" align="center">企业从业人员管理</th>
        <th field="isDel" width="10%" align="center" formatter="isdelformatter">启用/禁用</th>
    </tr>
    </thead>
</table>

<!-- 授證窗口 start-->

<div id="certificatory" class="easyui-window" data-options="modal:true,closed:true,iconCls:'icon-edit'"
     style="width:300px;height:370px;padding:10px;">
    <form id="certificatoryForm" method="post">
        <table align="center" style="margin-top:20px">
            <tr style="height: 30px">
                <td>证书类别:</td>
                <%--<td><input name="certificateType" id="certificateTypeAdd" class="easyui-textbox"
                           data-options="width:150,required:true"/></td>--%>

                <td>
                <select id="cc" name="certificateType" class="easyui-combobox" style="width:200px;">
                    <option>安防工程企业设计施工维护资质证书</option>
                    <option>安防行业企业信用等级证书</option>
                </select>
                </td>
                <input name="companyId" id="companyId" type="hidden"/>
                <td>单位名称:</td>
                <td><input name="companyName" id="companyNameAdd" class="easyui-textbox"
                           data-options="width:150,required:true"/></td>
            </tr>
            <tr style="height: 30px">
                <td>等级:</td>
                <td><input name="certificateLevel" id="certificateLevelAdd" class="easyui-textbox"
                           data-options="width:150,required:true"/></td>
                <%--<td><select id="cc" name="certificateLevel" class="easyui-combobox" style="width:200px;">
                    <option>一级</option>
                    <option>二级</option>
                    <option>三级级</option>
                </select></td>--%>
                <td>证书编号:</td>
                <td><input name="certificateNum" id="certificateNumAdd" class="easyui-textbox"
                           data-options="width:150,required:true"/>
                </td>
            </tr>
            <tr style="height: 30px">
                <td>证书有效期:</td>
                <td><input name="certificateValidity" id="certificateValidityAdd" class="easyui-datetimebox"
                           data-options="width:150,required:true"/>
                </td>
            </tr>
        </table>
    </form>
    <!-- 授證窗口 end-->


    <script>
        $(function () {
            /* 分页 */
            var pager = $('#dg').datagrid().datagrid('getPager');

        })
        // 重新载入当前页面数据
        function refresh() {
            $('#dg').datagrid('reload');
        }
        //启用/删除formatter
        function isdelformatter(value, row, index) {
            if (value == "1") {
                return '<span><a href="#" style="text-decoration:none;color:green" onclick=qidel(' + row.userId + ',' + value + '); >已 启 用</a></span>';
            } else if (value == "2") {
                return '<span><a href="#" style="text-decoration:none;color:red" onclick=qidel(' + row.userId + ',' + value + '); >已 禁 用</a></span>';
            } else {
                return value;
            }
        }

        //启用/删除
        function qidel(id, value) {
            var isDel = "";
            var delName = "";
            if (value == '1') {
                isDel = '2';
                delName = "禁用";
            }
            if (value == '2') {
                isDel = '1';
                delName = "启用";
            }

            $.messager.confirm('确认', '您确认想要 [ ' + delName + ' ] 数据吗？', function (r) {
                if (r) {
                    $.ajax({
                        url: '<%=basePath %>user/updateUser',
                        type: 'post',
                        data: {
                            "id": id,
                            "isDel": isDel
                        },
                        dataType: 'json',
                        error: function () {
                            $.messager.alert("提示", delName + "异常", "error");
                        },
                        success: function (map) {
                            var row = map.row;
                            if (row >= 0) {
                                $.messager.alert("提示", delName + "成功", "info");
                                $('#dg').datagrid("reload");
                                return;
                            } else {
                                $.messager.alert("提示", delName + "失败", "error");
                                return;
                            }
                        }
                    });
                }
            });
        }
        /* 点击搜索时触发 */
        function init() {
            var delName = "查询用户";
            var userId = $("#userId").val().replace(/\s/g, "");//登录账户
            var name = $("#name").val().replace(/\s/g, "");//显示名字
            $('#dg').datagrid({
                url: '<%=basePath %>companyMange/queryCompanyList?dt=' + new Date().getTime(),
                queryParams: {
                    userName: userId,
                    showName: name
                }

            });
        }
        /* 点击重置时触发 */
        function chongzhi() {
            $('#userName').textbox('clear');
            $('#showName').textbox('clear');
        }
        /*查看企业基本信息*/

        function viewCompanyBase() {
            var row = $('#dg').datagrid('getSelected');
            if (row == null || row == "") {
                $.messager.alert("友情提示", "请先选中一行数据", "error");
                return;
            }
            var row = $('#dg').datagrid('getSelected');
            var userId = row.userId;

            var url = 'toPage?urlStr=company_base_info&userId=' + userId;

            var backValue = '';
            backValue = window.open(url, "", 'edge:Raised;center:Yes;help:Yes;resizable:no;status:No;dialogWidth:1200px;DialogHeight=650px');

            if (backValue == "success") {
                $('#dg').datagrid("reload");
            }
        }


        function queryCompanyBase() {
            var row = $('#dg').datagrid('getSelected');
            if (row == null || row == "") {
                $.messager.alert("友情提示", "请先选中一行数据", "error");
                return;
            }
            var userId = row.userId;
            window.location.href = "/companyBase/baseInfo?userId=" + userId;

        }


        /*查看企业从业人员*/
        function viewEmployee() {
            var row = $('#dg').datagrid('getSelected');
            if (row == null || row == "") {
                $.messager.alert("友情提示", "请先选中一行数据", "error");
                return;
            }
            var row = $('#dg').datagrid('getSelected');
            var userId = row.userId;

            var url = 'toPage?urlStr=company_employee_issue&userId=' + userId;

            var backValue = '';
            backValue = window.open(url, "", 'edge:Raised;center:Yes;help:Yes;resizable:no;status:No;dialogWidth:1200px;DialogHeight=650px');

            if (backValue == "success") {
                $('#dg').datagrid("reload");
            }
        }


        function viewcertificatoryCampany() {
            var row = $('#dg').datagrid('getSelected');
            if (row == null || row == "") {
                $.messager.alert("友情提示", "请先选中一行数据", "error");
                return;
            }
            var row = $('#dg').datagrid('getSelected');
            var companyId = row.userId;

            var url = 'toPage?urlStr=certificatory_campany&companyId=' + companyId;

            var backValue = '';
            backValue = window.open(url, "", 'edge:Raised;center:Yes;help:Yes;resizable:no;status:No;dialogWidth:1200px;DialogHeight=650px');

            if (backValue == "success") {
                $('#dg').datagrid("reload");
            }
        }


        function queryEmployee() {
            var row = $('#dg').datagrid('getSelected');
            if (row == null || row == "") {
                $.messager.alert("友情提示", "请先选中一行数据", "error");
                return;
            }
            var userId = row.userId;
            window.location.href = "/companyBase/baseInfo?userId=" + userId;
        }


        /*授予证书*/
        function certificatoryCampany() {
            var row = $('#dg').datagrid('getSelected');
            if (row == null || row == "") {
                $.messager.alert("友情提示", "请先选中一行数据", "error");
                return;
            }
            $('#certificatoryForm').form('reset');


            $("#companyId").val(row.userId);

            $('#certificatory').show();
            $('#certificatory').dialog({
                title: '颁证',
                width: 650,
                height: 450,
                closed: false,
                cache: false,
                modal: true,
                buttons: [{
                    text: '保存',
                    iconCls: 'icon-ok',
                    handler: function () {

                        if ($("#certificatoryForm").form('validate')) {
                            $.ajax({
                                url: '<%=basePath %>companyMange/addCertificatoryCampany',
                                type: 'post', data: $("#certificatoryForm").serialize(),
                                dataType: 'json',
                                error: function () {
                                    $.messager.alert("友情提示", "系统异常,请稍后尝试", "error");
                                },
                                success: function (data) {
                                    var row = data.row;
                                    var msg = data.msg;

                                    if (row >= 0) {
                                        $.messager.alert("友情提示", "[授证成功!]", "info");
                                        $('#certificatory').dialog('close');
                                        $('#dg').datagrid("reload");
                                    } else {
                                        $.messager.alert("友情提示", "[授证失败!]", "info");
                                    }

                                }
                            });
                        }
                        else {
                            alert("form 无效")

                        }
                    }
                }, {
                    text: '退出',
                    iconCls: 'icon-no',
                    handler: function () {
                        $('#certificatory').dialog('close');
                    }
                }]
            });
        }


        function
        certificatoryCampany2() {
            var row = $('#dg').datagrid('getSelected');
            if (row == null || row == "") {
                $.messager.alert("友情提示", "请先选中一行数据", "error");
                return;
            }
            var userId = row.userId;
            window.location.href = "/companyBase/baseInfo?userId=" + userId;
        }
    </script>

</body>
</html>